#ifndef GAMESETTINGS_H
#define GAMESETTINGS_H

#include <QObject>
#include <QColor>
#include <QMap>
#include <QLinearGradient>
#include <QVariant>
#include <QPen>
#include "../DataStructure/Enums.h"

class ControlPanel;
class DotView;
class QWidget;
class MainWindow;


class GameSettings : public QObject
{
    Q_OBJECT
private:
    GameSettings(QObject *parent = 0);
    void loadPreference();

public slots:
        void savePreference();

public:    
    Game::Player playerTurn();
    QColor playerColor(Game::Player player);
    QString playerName(Game::Player player);
    QVariant setting(Game::Setting settingName);
    QLinearGradient brush(Game::Setting settingName);
    QLinearGradient brush(QColor color);
    QLinearGradient brush(Game::Player player);
    QPen pen(Game::Setting settingName);
    QPen pen(QColor color);
    QPen pen(Game::Player player);
    QWidget *mostTopWnd()const;
    bool inputFromUserToSelectTurn();
    bool playingWithComputer();
    QPoint integerSettingRange(Game::Setting setting)const;
    QString modeName();

    static GameSettings *me();
    static const Game::Setting UIntStart = Game::DotsPerRow;
    static const Game::Setting UIntEnd = Game::FieldMargin;
    static const Game::Setting ColorStart = Game::BGColor;
    static const Game::Setting ColorEnd = Game::ProgressBar;

signals:
    void settingChanged();
    void gameSettingChanged(Game::Setting set);
    void playerNameChanged(Game::Player player);
    void playerColorChanged(Game::Player player);

private:
    void setMostTopWnd(QWidget *pWnd);
    void setPlayerTurn(Game::Player player);
    void setSetting(Game::Setting settingName,QVariant value);
    QVariant defaultValue(Game::Setting settingName);
    void setPlayerColor(Game::Player player,QColor color);
    void setPlayerName(Game::Player player,QString name);
    void setPlayWithComputer(bool bPlay);
    void setIntegerSettingRange(Game::Setting setting,const QPoint value);
    void rethinkAboutSomeIntergerSettingsRange();
    void everFirstTimeSetting();

private:
    QColor mPlayerColors[3];
    QString mPlayerName[3];
    QMap<int,QVariant> mSettingsMap;
    QMap<int,QPoint> mIntegerSettingRanges;
    Game::Player mPlayerTurn;
    QWidget *mpMostParentWnd;
    static GameSettings *mpMe;
    bool mbPlayWithComputer;
    bool mbSettingsLoaded;

    friend class ControlPanel;
    friend class MainWindow;
};

#endif // GAMESETTINGS_H
